﻿using Lamex.Base;
using System;
using System.Collections.Generic;
using System.Data;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Lamex.mDashboard.Common
{
    public class NcUploadHelper
    {
        #region
        private string _partnum;
        public string partnum
        {
            set { _partnum = value; }
            get { return _partnum; }
        }

        private string _drawingnum;
        public string drawingnum
        {
            set { _drawingnum = value; }
            get { return _drawingnum; }
        }

        string Sub_Pro_Format_1 = string.Empty;
        string Sub_Pro_Format_2 = string.Empty;
        string Sub_Pro_Format_3 = string.Empty;
        string Sub_Pro_Format_4 = string.Empty;
        string Sub_Pro_Edge_1 = string.Empty;
        string Sub_Pro_Edge_2 = string.Empty;
        string Sub_Pro_Edge_3 = string.Empty;
        string Sub_Pro_Edge_4 = string.Empty;
        string Sub_Pro_Corner_1 = string.Empty;
        string Sub_Pro_Corner_2 = string.Empty;
        string Sub_Pro_Corner_3 = string.Empty;
        string Sub_Pro_Corner_4 = string.Empty;

        string EB_1 = string.Empty;
        string EB_2 = string.Empty;
        string EB_3 = string.Empty;
        string EB_4 = string.Empty;

        string Case_Code_1 = string.Empty;
        string Case_Code_2 = string.Empty;
        string Case_Code_3 = string.Empty;
        string Case_Code_4 = string.Empty;

        string T1 = string.Empty;
        string T2 = string.Empty;
        string T3 = string.Empty;
        string T4 = string.Empty;

        string Groove_Bottom_1 = string.Empty;
        string Groove_Bottom_2 = string.Empty;
        string Groove_Bottom_3 = string.Empty;
        string Groove_Bottom_4 = string.Empty;
        string Groove_Side_1 = string.Empty;
        string Groove_Side_2 = string.Empty;
        string Groove_Side_3 = string.Empty;
        string Groove_Side_4 = string.Empty;
        string Groove_1 = string.Empty;
        string Groove_2 = string.Empty;
        string Groove_3 = string.Empty;
        string Groove_4 = string.Empty;
        #endregion

        ///// <summary>
        ///// 将excel中的数据导入到DataTable中
        ///// </summary>
        ///// <param name="fileName">excel文件全路径名称</param>
        ///// <param name="isFirstRowColumn">第一行是否是DataTable的列名</param>
        ///// <returns>返回的DataTable</returns>
        //public DataTable ExcelToDataTable(string fileName, bool isFirstRowColumn)
        //{
        //    IWorkbook workbook = null;
        //    FileStream fs = null;
        //    ISheet sheet = null;
        //    DataTable data = new DataTable();
        //    int startRow = 0;
        //    try
        //    {
        //        fs = new FileStream(fileName, FileMode.Open, FileAccess.Read);
        //        //if (fileName.IndexOf(".xlsx") > 0) // 2007版本
        //        //    workbook = new XSSFWorkbook(fs);
        //        //else if (fileName.IndexOf(".xls") > 0) // 2003版本
        //        //    workbook = new HSSFWorkbook(fs);
        //        workbook = new XSSFWorkbook(fs);
        //        sheet = workbook.GetSheetAt(0);
        //        if (sheet != null)
        //        {
        //            IRow firstRow = sheet.GetRow(0);
        //            int cellCount = firstRow.LastCellNum; //一行最后一个cell的编号 即总的列数

        //            if (isFirstRowColumn)
        //            {
        //                for (int i = firstRow.FirstCellNum; i < cellCount; ++i)
        //                {
        //                    ICell cell = firstRow.GetCell(i);
        //                    if (cell != null)
        //                    {
        //                        string cellValue = cell.StringCellValue;
        //                        if (!string.IsNullOrEmpty(cellValue))
        //                        {
        //                            DataColumn column = new DataColumn(cellValue);
        //                            data.Columns.Add(column);
        //                        }
        //                    }
        //                }
        //                startRow = sheet.FirstRowNum + 1;
        //            }
        //            else
        //            {
        //                startRow = sheet.FirstRowNum;
        //            }

        //            //最后一列的标号
        //            int rowCount = sheet.LastRowNum;
        //            for (int i = startRow; i <= rowCount; ++i)
        //            {
        //                IRow row = sheet.GetRow(i);
        //                if (row == null) continue; //没有数据的行默认是null　　　　　　　

        //                DataRow dataRow = data.NewRow();
        //                for (int j = row.FirstCellNum; j < cellCount; ++j)
        //                {
        //                    if (row.GetCell(j) != null) //同理，没有数据的单元格都默认是null
        //                    {
        //                        switch (row.GetCell(j).CellType)
        //                        {
        //                            case CellType.Blank:
        //                                dataRow[j] = "";
        //                                break;
        //                            case CellType.Numeric:
        //                                short format = row.GetCell(j).CellStyle.DataFormat;
        //                                if (format == 14 || format == 31 || format == 57 || format == 58)
        //                                    dataRow[j] = row.GetCell(j).DateCellValue;
        //                                else
        //                                    dataRow[j] = row.GetCell(j).ToString();
        //                                break;
        //                            case CellType.String:
        //                                dataRow[j] = row.GetCell(j).StringCellValue;
        //                                break;
        //                            case CellType.Formula://单元格有函数
        //                                XSSFFormulaEvaluator e = new XSSFFormulaEvaluator(row.GetCell(j).Sheet.Workbook);
        //                                e.EvaluateInCell(row.GetCell(j));
        //                                short formatDate = row.GetCell(j).CellStyle.DataFormat;
        //                                if (formatDate == 14 || formatDate == 31 || formatDate == 57 || formatDate == 58)
        //                                    dataRow[j] = row.GetCell(j).DateCellValue;
        //                                else
        //                                    dataRow[j] = row.GetCell(j).ToString();
        //                                break;
        //                        }
        //                        //dataRow[j] = row.GetCell(j).ToString();
        //                    }
        //                }
        //                data.Rows.Add(dataRow);
        //            }
        //        }

        //        return data;
        //    }
        //    catch (Exception ex)
        //    {
        //        MessageBox.Show(ex.Message);
        //        return null;
        //    }
        //}
        /// <summary>
        /// 以逗号拆分字符串
        /// 若字段中包含逗号,则对其进行拼接处理
        /// 最后去除字段的双引号
        /// </summary>
        /// <param name="splitStr"></param>
        /// <returns></returns>
        private static string[] SplitStringWithComma(string splitStr)
        {
            var newstr = string.Empty;
            List<string> sList = new List<string>();
            bool isSplice = false;
            string[] array = splitStr.Split(new char[] { ',' });
            foreach (var str in array)
            {
                if (!string.IsNullOrEmpty(str) && str.IndexOf('"') > -1)
                {
                    var firstchar = str.Substring(0, 1);

                    var lastchar = string.Empty;

                    if (str.Length > 0)
                    {
                        lastchar = str.Substring(str.Length - 1, 1);
                    }
                    if (firstchar.Equals("\"") && !lastchar.Equals("\""))
                    {
                        isSplice = true;
                    }
                    if (lastchar.Equals("\""))
                    {
                        if (!isSplice)
                            newstr += str;
                        else
                            newstr = newstr + "," + str;
                        isSplice = false;
                    }
                }
                else
                {
                    if (string.IsNullOrEmpty(newstr))
                        newstr += str;
                }
                if (isSplice)
                {
                    //添加因拆分时丢失的逗号
                    if (string.IsNullOrEmpty(newstr))
                        newstr += str;
                    else
                        newstr = newstr + "," + str;
                }
                else
                {
                    sList.Add(newstr.Replace("\"", "").Trim());//去除字符中的双引号和首尾空格
                    newstr = string.Empty;
                }
            }

            return sList.ToArray();

        }

        /// <summary>
        /// CSV转DataTable
        /// </summary>
        /// <param name="fileName">文件路径全名称</param>
        /// <param name="IsFirst">第一行是否为标题</param>
        /// <returns></returns>
        public DataTable CsvToDataTable(string fileName, bool IsFirst)
        {
            DataTable dt = new DataTable();
            FileStream fs = new FileStream(fileName, FileMode.Open, FileAccess.Read);
            StreamReader sr = new StreamReader(fs, Encoding.Default);
            //记录每次读取的一行记录
            string strLine = "";
            //记录每行记录中的各字段内容
            string[] aryLine;
            //标示列数
            int columnCount = 0;
            //逐行读取CSV中的数据
            while ((strLine = sr.ReadLine()) != null)
            {
                if (string.IsNullOrEmpty(strLine))
                {
                    continue;
                }
                //aryLine = strLine.Replace(" ", "").Split(new string[] { "\"," }, StringSplitOptions.None);
                //双引号内的逗号不分割  双引号外的逗号进行分割
                aryLine = SplitStringWithComma(strLine);
                if (IsFirst == true)
                {
                    IsFirst = false;
                    columnCount = aryLine.Length - 1;//去掉最后一列
                    //创建列
                    for (int i = 0; i < columnCount; i++)
                    {
                        DataColumn dc = new DataColumn(aryLine[i].Trim());
                        dt.Columns.Add(dc);
                    }
                }
                else
                {
                    DataRow dr = dt.NewRow();
                    for (int j = 0; j < columnCount; j++)
                    {
                        dr[j] = aryLine[j].Trim();
                    }
                    dt.Rows.Add(dr);
                }
            }
            sr.Close();
            fs.Close();
            return dt;
        }

        public bool IsReturnSJ(string fileName)
        {
            try
            {
                DataTable dt = CsvToDataTable(fileName, true);
                //CSVHelper cSVHelper = new CSVHelper(fileName);
                //DataTable dt = cSVHelper.ExcelToDataTable("PTD", true);
                if (dt == null || dt.Rows.Count <= 0)
                {
                    MessageBox.Show("打开的EXCEL文件无数据，请检查！");
                    return false;
                }
                else
                {
                    if (Insert_Initial_Data_SJ(dt) && Insert_EdgebandProgram_SJ(dt))
                        return true;
                    else
                        return false;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                return false;
            }
        }

        #region Insert_Initial_Data_SJ
        private bool Insert_Initial_Data_SJ(DataTable dt)
        {
            #region 列名参数定义
            string 标识 = string.Empty;
            string 文件编号 = string.Empty;
            string 制图 = string.Empty;
            string 审核 = string.Empty;
            string 生效日期 = string.Empty;
            string 产品类别 = string.Empty;
            string 图号 = string.Empty;
            string 型号 = string.Empty;
            string 部件编号 = string.Empty;
            string 描述 = string.Empty;
            string 表面处理 = string.Empty;
            string 材料说明 = string.Empty;
            string 木纹方向 = string.Empty;
            string 厚度 = string.Empty;
            string 阔度_1 = string.Empty;
            string 深度_1 = string.Empty;
            string 阔度_2 = string.Empty;
            string 深度_2 = string.Empty;
            string 单开_W = string.Empty;
            string 单开_D = string.Empty;
            string 单开尺寸 = string.Empty;
            string 双开_W = string.Empty;
            string 双开_D = string.Empty;
            string 双开尺寸 = string.Empty;
            string 封边_C1 = string.Empty;
            string 封边_C2 = string.Empty;
            string 封边_C3 = string.Empty;
            string 封边_C4 = string.Empty;
            string 封边_T1 = string.Empty;
            string 封边_T2 = string.Empty;
            string 封边_T3 = string.Empty;
            string 封边_T4 = string.Empty;
            string 封边_S1 = string.Empty;
            string 封边_S2 = string.Empty;
            string 封边_S3 = string.Empty;
            string 封边_S4 = string.Empty;
            string 工序_01 = string.Empty;
            string 工序_02 = string.Empty;
            string 工序_03 = string.Empty;
            string 工序_04 = string.Empty;
            string 工序_05 = string.Empty;
            string 工序_06 = string.Empty;
            string 工序_07 = string.Empty;
            string 工序_08 = string.Empty;
            string 工序_09 = string.Empty;
            string 工序_10 = string.Empty;
            string 底槽1_CD = string.Empty;
            string 底槽2_CD = string.Empty;
            string 底槽3_CD = string.Empty;
            string 底槽4_CD = string.Empty;
            string 侧槽1_CD = string.Empty;
            string 侧槽2_CD = string.Empty;
            string 侧槽3_CD = string.Empty;
            string 侧槽4_CD = string.Empty;
            string 检查标识 = string.Empty;
            string ECN生效 = string.Empty;
            string 旋转标识 = string.Empty;
            string C_阔度_1 = string.Empty;
            string C_阔度_2 = string.Empty;
            string C_封边_S1 = string.Empty;
            string C_封边_S2 = string.Empty;
            string C_封边_S3 = string.Empty;
            string C_封边_S4 = string.Empty;
            string C_底槽1_CD = string.Empty;
            string C_底槽2_CD = string.Empty;
            string C_底槽3_CD = string.Empty;
            string C_底槽4_CD = string.Empty;
            string C_侧槽1_CD = string.Empty;
            string C_侧槽2_CD = string.Empty;
            string C_侧槽3_CD = string.Empty;
            string C_侧槽4_CD = string.Empty;
            string C_封边_T1 = string.Empty;
            string C_封边_T2 = string.Empty;
            string C_封边_T3 = string.Empty;
            string C_封边_T4 = string.Empty;

            #endregion

            if (dt.Rows.Count > 0)
            {
                //int columnNum = 0;
                //columnNum = dt.Columns.Count;

                for (int j = 0; j < dt.Rows.Count; j++)
                {
                    for (int i = 0; i < dt.Columns.Count; i++)
                    {
                        #region Get value
                        if (dt.Columns[i].ColumnName.ToString() == "标识")
                        {
                            标识 = dt.Rows[j][i].ToString();
                        }
                        else
                        {
                        }
                        if (dt.Columns[i].ColumnName.ToString() == "文件编号")
                        {
                            文件编号 = dt.Rows[j][i].ToString();
                        }
                        else
                        {
                        }
                        if (dt.Columns[i].ColumnName.ToString() == "制图")
                        {
                            制图 = dt.Rows[j][i].ToString();
                            //MessageBox.Show(制图);
                        }
                        else
                        {
                        }
                        if (dt.Columns[i].ColumnName.ToString() == "审核")
                        {
                            审核 = dt.Rows[j][i].ToString();
                        }
                        else
                        {
                        }
                        if (dt.Columns[i].ColumnName.ToString() == "生效日期")
                        {
                            生效日期 = dt.Rows[j][i].ToString();
                        }
                        else
                        {
                        }
                        if (dt.Columns[i].ColumnName.ToString() == "产品类别")
                        {
                            产品类别 = dt.Rows[j][i].ToString();
                        }
                        else
                        {
                        }
                        if (dt.Columns[i].ColumnName.ToString() == "图号")
                        {
                            图号 = dt.Rows[j][i].ToString();
                        }
                        else
                        {
                        }
                        if (dt.Columns[i].ColumnName.ToString() == "型号")
                        {
                            型号 = dt.Rows[j][i].ToString();
                        }
                        else
                        {
                        }
                        if (dt.Columns[i].ColumnName.ToString() == "部件编号")
                        {
                            部件编号 = dt.Rows[j][i].ToString();
                        }
                        else
                        {
                        }
                        if (dt.Columns[i].ColumnName.ToString() == "描述")
                        {
                            描述 = dt.Rows[j][i].ToString();
                        }
                        else
                        {
                        }
                        if (dt.Columns[i].ColumnName.ToString() == "表面处理")
                        {
                            表面处理 = dt.Rows[j][i].ToString();
                        }
                        else
                        {
                        }
                        if (dt.Columns[i].ColumnName.ToString() == "材料说明")
                        {
                            材料说明 = dt.Rows[j][i].ToString();
                        }
                        else
                        {
                        }
                        if (dt.Columns[i].ColumnName.ToString() == "木纹方向")
                        {
                            木纹方向 = dt.Rows[j][i].ToString();
                        }
                        else
                        {
                        }
                        if (dt.Columns[i].ColumnName.ToString() == "厚度")
                        {
                            厚度 = dt.Rows[j][i].ToString();
                        }
                        else
                        {
                        }
                        if (dt.Columns[i].ColumnName.ToString() == "阔度_1")
                        {
                            阔度_1 = dt.Rows[j][i].ToString();
                        }
                        else
                        {
                        }
                        if (dt.Columns[i].ColumnName.ToString() == "深度_1")
                        {
                            深度_1 = dt.Rows[j][i].ToString();
                        }
                        else
                        {
                        }
                        if (dt.Columns[i].ColumnName.ToString() == "阔度_2")
                        {
                            阔度_2 = dt.Rows[j][i].ToString();
                        }
                        else
                        {
                        }
                        if (dt.Columns[i].ColumnName.ToString() == "深度_2")
                        {
                            深度_2 = dt.Rows[j][i].ToString();
                        }
                        else
                        {
                        }
                        if (dt.Columns[i].ColumnName.ToString() == "单开_W")
                        {
                            单开_W = dt.Rows[j][i].ToString();
                        }
                        else
                        {
                        }
                        if (dt.Columns[i].ColumnName.ToString() == "单开_D")
                        {
                            单开_D = dt.Rows[j][i].ToString();
                        }
                        else
                        {
                        }
                        if (dt.Columns[i].ColumnName.ToString() == "单开尺寸")
                        {
                            单开尺寸 = dt.Rows[j][i].ToString();
                        }
                        else
                        {
                        }
                        if (dt.Columns[i].ColumnName.ToString() == "双开_W")
                        {
                            双开_W = dt.Rows[j][i].ToString();
                        }
                        else
                        {
                        }
                        if (dt.Columns[i].ColumnName.ToString() == "双开_D")
                        {
                            双开_D = dt.Rows[j][i].ToString();
                        }
                        else
                        {
                        }
                        if (dt.Columns[i].ColumnName.ToString() == "双开尺寸")
                        {
                            双开尺寸 = dt.Rows[j][i].ToString();
                        }
                        else
                        {
                        }
                        if (dt.Columns[i].ColumnName.ToString() == "封边_C1")
                        {
                            封边_C1 = dt.Rows[j][i].ToString();
                        }
                        else
                        {
                        }
                        if (dt.Columns[i].ColumnName.ToString() == "封边_C2")
                        {
                            封边_C2 = dt.Rows[j][i].ToString();
                        }
                        else
                        {
                        }
                        if (dt.Columns[i].ColumnName.ToString() == "封边_C3")
                        {
                            封边_C3 = dt.Rows[j][i].ToString();
                        }
                        else
                        {
                        }
                        if (dt.Columns[i].ColumnName.ToString() == "封边_C4")
                        {
                            封边_C4 = dt.Rows[j][i].ToString();
                        }
                        else
                        {
                        }
                        if (dt.Columns[i].ColumnName.ToString() == "封边_T1")
                        {
                            封边_T1 = dt.Rows[j][i].ToString();
                        }
                        else
                        {
                        }
                        if (dt.Columns[i].ColumnName.ToString() == "封边_T2")
                        {
                            封边_T2 = dt.Rows[j][i].ToString();
                        }
                        else
                        {
                        }
                        if (dt.Columns[i].ColumnName.ToString() == "封边_T3")
                        {
                            封边_T3 = dt.Rows[j][i].ToString();
                        }
                        else
                        {
                        }
                        if (dt.Columns[i].ColumnName.ToString() == "封边_T4")
                        {
                            封边_T4 = dt.Rows[j][i].ToString();
                        }
                        else
                        {
                        }
                        if (dt.Columns[i].ColumnName.ToString() == "封边_S1")
                        {
                            封边_S1 = dt.Rows[j][i].ToString();
                        }
                        else
                        {
                        }
                        if (dt.Columns[i].ColumnName.ToString() == "封边_S2")
                        {
                            封边_S2 = dt.Rows[j][i].ToString();
                        }
                        else
                        {
                        }
                        if (dt.Columns[i].ColumnName.ToString() == "封边_S3")
                        {
                            封边_S3 = dt.Rows[j][i].ToString();
                        }
                        else
                        {
                        }
                        if (dt.Columns[i].ColumnName.ToString() == "封边_S4")
                        {
                            封边_S4 = dt.Rows[j][i].ToString();
                        }
                        else
                        {
                        }
                        if (dt.Columns[i].ColumnName.ToString() == "工序_01")
                        {
                            工序_01 = dt.Rows[j][i].ToString();
                        }
                        else
                        {
                        }
                        if (dt.Columns[i].ColumnName.ToString() == "工序_02")
                        {
                            工序_02 = dt.Rows[j][i].ToString();
                        }
                        else
                        {
                        }
                        if (dt.Columns[i].ColumnName.ToString() == "工序_03")
                        {
                            工序_03 = dt.Rows[j][i].ToString();
                        }
                        else
                        {
                        }
                        if (dt.Columns[i].ColumnName.ToString() == "工序_04")
                        {
                            工序_04 = dt.Rows[j][i].ToString();
                        }
                        else
                        {
                        }
                        if (dt.Columns[i].ColumnName.ToString() == "工序_05")
                        {
                            工序_05 = dt.Rows[j][i].ToString();
                        }
                        else
                        {
                        }
                        if (dt.Columns[i].ColumnName.ToString() == "工序_06")
                        {
                            工序_06 = dt.Rows[j][i].ToString();
                        }
                        else
                        {
                        }
                        if (dt.Columns[i].ColumnName.ToString() == "工序_07")
                        {
                            工序_07 = dt.Rows[j][i].ToString();
                        }
                        else
                        {
                        }
                        if (dt.Columns[i].ColumnName.ToString() == "工序_08")
                        {
                            工序_08 = dt.Rows[j][i].ToString();
                        }
                        else
                        {
                        }
                        if (dt.Columns[i].ColumnName.ToString() == "工序_09")
                        {
                            工序_09 = dt.Rows[j][i].ToString();
                        }
                        else
                        {
                        }
                        if (dt.Columns[i].ColumnName.ToString() == "工序_10")
                        {
                            工序_10 = dt.Rows[j][i].ToString();
                        }
                        else
                        {
                        }
                        if (dt.Columns[i].ColumnName.ToString() == "底槽1_CD")
                        {
                            底槽1_CD = dt.Rows[j][i].ToString();
                        }
                        else
                        {
                        }
                        if (dt.Columns[i].ColumnName.ToString() == "底槽2_CD")
                        {
                            底槽2_CD = dt.Rows[j][i].ToString();
                        }
                        else
                        {
                        }
                        if (dt.Columns[i].ColumnName.ToString() == "底槽3_CD")
                        {
                            底槽3_CD = dt.Rows[j][i].ToString();
                        }
                        else
                        {
                        }
                        if (dt.Columns[i].ColumnName.ToString() == "底槽4_CD")
                        {
                            底槽4_CD = dt.Rows[j][i].ToString();
                        }
                        else
                        {
                        }
                        if (dt.Columns[i].ColumnName.ToString() == "侧槽1_CD")
                        {
                            侧槽1_CD = dt.Rows[j][i].ToString();
                        }
                        else
                        {
                        }
                        if (dt.Columns[i].ColumnName.ToString() == "侧槽2_CD")
                        {
                            侧槽2_CD = dt.Rows[j][i].ToString();
                        }
                        else
                        {
                        }
                        if (dt.Columns[i].ColumnName.ToString() == "侧槽3_CD")
                        {
                            侧槽3_CD = dt.Rows[j][i].ToString();
                        }
                        else
                        {
                        }
                        if (dt.Columns[i].ColumnName.ToString() == "侧槽4_CD")
                        {
                            侧槽4_CD = dt.Rows[j][i].ToString();
                        }
                        else
                        {
                        }
                        if (dt.Columns[i].ColumnName.ToString() == "检查标识")
                        {
                            检查标识 = dt.Rows[j][i].ToString();
                        }
                        else
                        {
                        }
                        if (dt.Columns[i].ColumnName.ToString() == "ECN生效")
                        {
                            ECN生效 = dt.Rows[j][i].ToString();
                        }
                        else
                        {
                        }
                        if (dt.Columns[i].ColumnName.ToString() == "旋转标识")
                        {
                            旋转标识 = dt.Rows[j][i].ToString();
                        }
                        else
                        {
                        }
                        if (dt.Columns[i].ColumnName.ToString() == "C_阔度_1")
                        {
                            C_阔度_1 = dt.Rows[j][i].ToString();
                        }
                        else
                        {
                        }
                        if (dt.Columns[i].ColumnName.ToString() == "C_阔度_2")
                        {
                            C_阔度_2 = dt.Rows[j][i].ToString();
                        }
                        else
                        {
                        }
                        if (dt.Columns[i].ColumnName.ToString() == "C_封边_S1")
                        {
                            C_封边_S1 = dt.Rows[j][i].ToString();
                        }
                        else
                        {
                        }
                        if (dt.Columns[i].ColumnName.ToString() == "C_封边_S2")
                        {
                            C_封边_S2 = dt.Rows[j][i].ToString();
                        }
                        else
                        {
                        }
                        if (dt.Columns[i].ColumnName.ToString() == "C_封边_S3")
                        {
                            C_封边_S3 = dt.Rows[j][i].ToString();
                        }
                        else
                        {
                        }
                        if (dt.Columns[i].ColumnName.ToString() == "C_封边_S4")
                        {
                            C_封边_S4 = dt.Rows[j][i].ToString();
                        }
                        else
                        {
                        }
                        if (dt.Columns[i].ColumnName.ToString() == "C_底槽1_CD")
                        {
                            C_底槽1_CD = dt.Rows[j][i].ToString();
                        }
                        else
                        {
                        }
                        if (dt.Columns[i].ColumnName.ToString() == "C_底槽2_CD")
                        {
                            C_底槽2_CD = dt.Rows[j][i].ToString();
                        }
                        else
                        {
                        }
                        if (dt.Columns[i].ColumnName.ToString() == "C_底槽3_CD")
                        {
                            C_底槽3_CD = dt.Rows[j][i].ToString();
                        }
                        else
                        {
                        }
                        if (dt.Columns[i].ColumnName.ToString() == "C_底槽4_CD")
                        {
                            C_底槽4_CD = dt.Rows[j][i].ToString();
                        }
                        else
                        {
                        }
                        if (dt.Columns[i].ColumnName.ToString() == "C_侧槽1_CD")
                        {
                            C_侧槽1_CD = dt.Rows[j][i].ToString();
                        }
                        else
                        {
                        }
                        if (dt.Columns[i].ColumnName.ToString() == "C_侧槽2_CD")
                        {
                            C_侧槽2_CD = dt.Rows[j][i].ToString();
                        }
                        else
                        {
                        }
                        if (dt.Columns[i].ColumnName.ToString() == "C_侧槽3_CD")
                        {
                            C_侧槽3_CD = dt.Rows[j][i].ToString();
                        }
                        else
                        {
                        }
                        if (dt.Columns[i].ColumnName.ToString() == "C_侧槽4_CD")
                        {
                            C_侧槽4_CD = dt.Rows[j][i].ToString();
                        }
                        else
                        {
                        }
                        if (dt.Columns[i].ColumnName.ToString() == "C_封边_T1")
                        {
                            C_封边_T1 = dt.Rows[j][i].ToString();
                        }
                        else
                        {
                        }
                        if (dt.Columns[i].ColumnName.ToString() == "C_封边_T2")
                        {
                            C_封边_T2 = dt.Rows[j][i].ToString();
                        }
                        else
                        {
                        }
                        if (dt.Columns[i].ColumnName.ToString() == "C_封边_T3")
                        {
                            C_封边_T3 = dt.Rows[j][i].ToString();
                        }
                        else
                        {
                        }
                        if (dt.Columns[i].ColumnName.ToString() == "C_封边_T4")
                        {
                            C_封边_T4 = dt.Rows[j][i].ToString();
                        }
                        else
                        {
                        }
                    }
                    #endregion

                    if (Check_edgingcode_status_SJ(C_封边_S1, C_封边_S2, C_封边_S3, C_封边_S4, 部件编号.ToUpper()) == false)
                    {
                        return false;
                    }

                    DelDuplicated_Initial_Data_SJ(部件编号.ToUpper());
                    //删除重复数据[LamexMESManager].[dbo].[IE_Part_SizeParmList]
                    DelDuplicated_IE_Part_SizeParmList(部件编号.ToUpper(), 部件编号.ToUpper());

                    #region Insert Data
                    string sql = string.Empty;
                    sql = sql + "INSERT INTO [Edgeband_Program].[dbo].[Initial_Data_SJ](Identification,File_Num,Drawer,Auditor,Effective_Date,Product_Category,Drawing_Num,Model,PartNumber,Description,Surface,Material_Description,GRAIN,Thickness,Width_1,Depth_1,Width_2,Depth_2,Cutting_W,Cutting_D,Cutting_Size,D_Cutting_W,D_Cutting_D,D_Cutting_Size,Edgeband_C1,Edgeband_C2,Edgeband_C3,Edgeband_C4,Edgeband_T1,Edgeband_T2,Edgeband_T3,Edgeband_T4,Edgeband_S1,Edgeband_S2,Edgeband_S3,Edgeband_S4,Procedure_01,Procedure_02,Procedure_03,Procedure_04,Procedure_05,Procedure_06,Procedure_07,Procedure_08,Procedure_09,Procedure_10,Groove_Bottom_1_CD,Groove_Bottom_2_CD,Groove_Bottom_3_CD,Groove_Bottom_4_CD,Groove_Side_1_CD,Groove_Side_2_CD,Groove_Side_3_CD,Groove_Side_4_CD,Check_Mark,ECN_Effect_Date,Rotation_Mark,C_Width_1,C_Width_2,C_Edgeband_S1,C_Edgeband_S2,C_Edgeband_S3,C_Edgeband_S4,C_Groove_Bottom_1_CD,C_Groove_Bottom_2_CD,C_Groove_Bottom_3_CD,C_Groove_Bottom_4_CD,C_Groove_Side_1_CD,C_Groove_Side_2_CD,C_Groove_Side_3_CD,C_Groove_Side_4_CD,C_Edgeband_T1,C_Edgeband_T2,C_Edgeband_T3,C_Edgeband_T4) VALUES(N'" + 标识 + "',";
                    sql = sql + "N'" + 文件编号 + "',N'" + 制图 + "',N'" + 审核 + "',N'" + 生效日期 + "',N'" + 产品类别 + "',N'" + 图号.ToUpper() + "',N'" + 型号 + "',N'" + 部件编号.ToUpper() + "',N'" + 描述 + "',N'" + 表面处理 + "',N'" + 材料说明 + "',N'" + 木纹方向 + "',N'" + 厚度 + "',N'" + 阔度_1 + "',N'" + 深度_1 + "',N'" + 阔度_2 + "',N'" + 深度_2 + "',N'" + 单开_W + "',N'" + 单开_D + "',N'" + 单开尺寸 + "',N'" + 双开_W + "',N'" + 双开_D + "',N'" + 双开尺寸 + "',N'" + 封边_C1 + "',N'" + 封边_C2 + "',N'" + 封边_C3 + "',N'" + 封边_C4 + "',N'" + 封边_T1 + "',N'" + 封边_T2 + "',N'" + 封边_T3 + "',N'" + 封边_T4 + "',";
                    sql = sql + "N'" + 封边_S1 + "',N'" + 封边_S2 + "',N'" + 封边_S3 + "',N'" + 封边_S4 + "',N'" + 工序_01 + "',N'" + 工序_02 + "',N'" + 工序_03 + "',N'" + 工序_04 + "',N'" + 工序_05 + "',N'" + 工序_06 + "',N'" + 工序_07 + "',N'" + 工序_08 + "',N'" + 工序_09 + "',N'" + 工序_10 + "',N'" + 底槽1_CD + "',N'" + 底槽2_CD + "',N'" + 底槽3_CD + "',N'" + 底槽4_CD + "',N'" + 侧槽1_CD + "',N'" + 侧槽2_CD + "',N'" + 侧槽3_CD + "',N'" + 侧槽4_CD + "',";
                    sql = sql + "N'" + 检查标识 + "',N'" + ECN生效 + "',N'" + 旋转标识 + "',N'" + C_阔度_1 + "',N'" + C_阔度_2 + "',N'" + C_封边_S1 + "',N'" + C_封边_S2 + "',N'" + C_封边_S3 + "',N'" + C_封边_S4 + "',N'" + C_底槽1_CD + "',N'" + C_底槽2_CD + "',N'" + C_底槽3_CD + "',N'" + C_底槽4_CD + "',N'" + C_侧槽1_CD + "',N'" + C_侧槽2_CD + "',N'" + C_侧槽3_CD + "',N'" + C_侧槽4_CD + "',N'" + C_封边_T1 + "',N'" + C_封边_T2 + "',N'" + C_封边_T3 + "',N'" + C_封边_T4 + "')";

                    //插入[LamexMESManager].[dbo].[IE_Part_SizeParmList]
                    sql = sql + ";" + @"INSERT INTO [LamexMESManager].[dbo].[IE_Part_SizeParmList](DWG_NO,PART_NO,WIDTH_1,WIDTH_2,DEPTH_1,DEPTH_2,THICK,UPDATE_TIME,UPDATE_USER)
                    VALUES('" + 部件编号.ToUpper() + "','" + 部件编号.ToUpper() + "'," + (阔度_1.Contains("*") ? "null" : 阔度_1) + "," + (阔度_2.Contains("*") ? "null" : 阔度_2) + "," + (深度_1.Contains("*") ? "null" : 深度_1) + "," + (深度_2.Contains("*") ? "null" : 深度_2) + "," + 厚度 + ",GETDATE(),'Initial Value')";
                    //更新[LamexMESManager].[dbo].[IE_Part_TaskList]
                    sql = sql + ";" + @"  update [LamexMESManager].[dbo].[IE_Part_TaskList] set PARM_FLAG='1' where PART_NO='" + 部件编号.ToUpper() + "' and DWG_NO='" + 部件编号.ToUpper() + "'";

                    int exct = BaseBuildSql.ExecuteNonQuery(sql); //DataBaseHelper.GetNonQueryEffectedRow(sql);
                    #endregion
                }
            }

            #region Correct Date Format(Effective_Date)

            string sqlcordate = string.Empty;
            sqlcordate = sqlcordate + "UPDATE [Edgeband_Program].[dbo].[Initial_Data_SJ] SET Effective_Date = CONVERT(NVARCHAR(30),CONVERT(DATETIME,Effective_Date,111),111) WHERE LEN(Effective_Date)>10";
            int Exesql = BaseBuildSql.ExecuteNonQuery(sqlcordate); //执行并返回受影响的行数

            #endregion

            #region Correct Date Format(ECN_Date)

            string sqlcorecndate = string.Empty;
            sqlcorecndate = sqlcorecndate + "UPDATE [Edgeband_Program].[dbo].[Initial_Data_SJ] SET ECN_Effect_Date = CONVERT(NVARCHAR(30),CONVERT(DATETIME,ECN_Effect_Date,111),111) WHERE LEN(ECN_Effect_Date)>10";
            int Exesqlecn = BaseBuildSql.ExecuteNonQuery(sqlcorecndate); //执行并返回受影响的行数       
            #endregion
            return true;
        }
        private bool Check_edgingcode_status_SJ(string edgingcode1, string edgingcode2, string edgingcode3, string edgingcode4, string partnumber)
        {
            try
            {
                #region Check edgingcode1           
                string sql = string.Empty;
                sql = sql + "SELECT EDGINGCODE FROM [Lamex_1207].[dbo].[TBL_EDGEMATERIAL](NOLOCK) WHERE EDGINGCODE = '" + edgingcode1 + "'";
                DataTable table1 = BaseBuildSql.GetDataTableBySql(sql);
                if (table1.Rows.Count <= 0)
                {
                    MessageBox.Show(partnumber + "的封边条1: " + edgingcode1 + " 在数据库不存在!", "提醒");
                    return false;
                }
                #endregion

                #region Check edgingcode2
                string sql2 = string.Empty;
                sql2 = sql2 + "SELECT EDGINGCODE FROM [Lamex_1207].[dbo].[TBL_EDGEMATERIAL](NOLOCK) WHERE EDGINGCODE = '" + edgingcode2 + "'";
                DataTable table2 = BaseBuildSql.GetDataTableBySql(sql2);
                if (table2.Rows.Count <= 0)
                {
                    MessageBox.Show(partnumber + "的封边条2: " + edgingcode2 + " 在数据库不存在!", "提醒");
                    return false;
                }
                #endregion

                #region Check edgingcode3
                string sql3 = string.Empty;
                sql3 = sql3 + "SELECT EDGINGCODE FROM [Lamex_1207].[dbo].[TBL_EDGEMATERIAL](NOLOCK) WHERE EDGINGCODE = '" + edgingcode3 + "'";
                DataTable table3 = BaseBuildSql.GetDataTableBySql(sql3);
                if (table3.Rows.Count <= 0)
                {

                    MessageBox.Show(partnumber + "的封边条3: " + edgingcode3 + " 在数据库不存在!", "提醒");
                    return false;
                }
                #endregion

                #region Check edgingcode4
                string sql4 = string.Empty;
                sql4 = sql4 + "SELECT EDGINGCODE FROM [Lamex_1207].[dbo].[TBL_EDGEMATERIAL](NOLOCK) WHERE EDGINGCODE = '" + edgingcode4 + "'";
                DataTable table4 = BaseBuildSql.GetDataTableBySql(sql4);
                if (table4.Rows.Count <= 0)
                {

                    MessageBox.Show(partnumber + "的封边条4: " + edgingcode4 + " 在数据库不存在!", "提醒");
                    return false;
                }
                #endregion
                return true;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                return false;
            }
        }
        private void DelDuplicated_Initial_Data_SJ(string PartNumber)
        {
            try
            {

                string sql = string.Empty;
                sql = sql + "SELECT * FROM [Edgeband_Program].[dbo].[Initial_Data_SJ](NOLOCK) WHERE PartNumber = '" + PartNumber + "'";
                DataTable table = BaseBuildSql.GetDataTableBySql(sql);
                if (table.Rows.Count != 0)
                {
                    string sql1 = string.Empty;
                    sql1 = sql1 + "DELETE FROM [Edgeband_Program].[dbo].[Initial_Data_SJ] WHERE PartNumber = '" + PartNumber + "'";
                    int i = BaseBuildSql.ExecuteNonQuery(sql1);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
        private void DelDuplicated_IE_Part_SizeParmList(string PartNumber, string DrawingNumber)
        {
            try
            {
                string sql = string.Empty;
                sql = sql + "SELECT * FROM [LamexMESManager].[dbo].[IE_Part_SizeParmList](NOLOCK) WHERE PART_NO = '" + PartNumber + "' AND DWG_NO= '" + DrawingNumber + "'";
                DataTable table = BaseBuildSql.GetDataTableBySql(sql);
                if (table.Rows.Count != 0)
                {
                    string sql1 = string.Empty;
                    sql1 = sql1 + "DELETE FROM [LamexMESManager].[dbo].[IE_Part_SizeParmList] WHERE PART_NO = '" + PartNumber + "' AND DWG_NO= '" + DrawingNumber + "'";
                    int i = BaseBuildSql.ExecuteNonQuery(sql1);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
        #endregion

        #region Insert_EdgebandProgram_SJ
        private bool Insert_EdgebandProgram_SJ(DataTable dt)
        {
            #region 列名参数定义
            string 标识 = string.Empty;
            string 文件编号 = string.Empty;
            string 制图 = string.Empty;
            string 审核 = string.Empty;
            string 生效日期 = string.Empty;
            string 产品类别 = string.Empty;
            string 图号 = string.Empty;
            string 型号 = string.Empty;
            string 部件编号 = string.Empty;
            string 描述 = string.Empty;
            string 表面处理 = string.Empty;
            string 材料说明 = string.Empty;
            string 木纹方向 = string.Empty;
            string 厚度 = string.Empty;
            string 阔度_1 = string.Empty;
            string 深度_1 = string.Empty;
            string 阔度_2 = string.Empty;
            string 深度_2 = string.Empty;
            string 单开_W = string.Empty;
            string 单开_D = string.Empty;
            string 单开尺寸 = string.Empty;
            string 双开_W = string.Empty;
            string 双开_D = string.Empty;
            string 双开尺寸 = string.Empty;
            string 封边_C1 = string.Empty;
            string 封边_C2 = string.Empty;
            string 封边_C3 = string.Empty;
            string 封边_C4 = string.Empty;
            string 封边_T1 = string.Empty;
            string 封边_T2 = string.Empty;
            string 封边_T3 = string.Empty;
            string 封边_T4 = string.Empty;
            string 封边_S1 = string.Empty;
            string 封边_S2 = string.Empty;
            string 封边_S3 = string.Empty;
            string 封边_S4 = string.Empty;
            string 工序_01 = string.Empty;
            string 工序_02 = string.Empty;
            string 工序_03 = string.Empty;
            string 工序_04 = string.Empty;
            string 工序_05 = string.Empty;
            string 工序_06 = string.Empty;
            string 工序_07 = string.Empty;
            string 工序_08 = string.Empty;
            string 工序_09 = string.Empty;
            string 工序_10 = string.Empty;
            string 底槽1_CD = string.Empty;
            string 底槽2_CD = string.Empty;
            string 底槽3_CD = string.Empty;
            string 底槽4_CD = string.Empty;
            string 侧槽1_CD = string.Empty;
            string 侧槽2_CD = string.Empty;
            string 侧槽3_CD = string.Empty;
            string 侧槽4_CD = string.Empty;
            string 检查标识 = string.Empty;
            string ECN生效 = string.Empty;
            string 旋转标识 = string.Empty;
            string C_阔度_1 = string.Empty;
            string C_阔度_2 = string.Empty;
            string C_封边_S1 = string.Empty;
            string C_封边_S2 = string.Empty;
            string C_封边_S3 = string.Empty;
            string C_封边_S4 = string.Empty;
            string C_底槽1_CD = string.Empty;
            string C_底槽2_CD = string.Empty;
            string C_底槽3_CD = string.Empty;
            string C_底槽4_CD = string.Empty;
            string C_侧槽1_CD = string.Empty;
            string C_侧槽2_CD = string.Empty;
            string C_侧槽3_CD = string.Empty;
            string C_侧槽4_CD = string.Empty;
            string C_封边_T1 = string.Empty;
            string C_封边_T2 = string.Empty;
            string C_封边_T3 = string.Empty;
            string C_封边_T4 = string.Empty;

            //For P&H Orientation
            string PuHOrientation = string.Empty;

            #endregion

            if (dt.Rows.Count > 0)
            {
                for (int j = 0; j < dt.Rows.Count; j++)
                {
                    if (dt.Columns.Count > 0)
                    {
                        for (int i = 0; i < dt.Columns.Count; i++)
                        {
                            #region Get Value

                            if (dt.Columns[i].ColumnName.ToString() == "封边_S1")
                            {
                                EB_1 = dt.Rows[j][i].ToString();
                                //MessageBox.Show(EB_1);
                            }
                            else
                            {
                            }
                            if (dt.Columns[i].ColumnName.ToString() == "封边_S2")
                            {
                                EB_2 = dt.Rows[j][i].ToString();
                                //MessageBox.Show(EB_2);
                            }
                            else
                            {
                            }
                            if (dt.Columns[i].ColumnName.ToString() == "封边_S3")
                            {
                                EB_3 = dt.Rows[j][i].ToString();
                                //MessageBox.Show(EB_3);
                            }
                            else
                            {
                            }
                            if (dt.Columns[i].ColumnName.ToString() == "封边_S4")
                            {
                                EB_4 = dt.Rows[j][i].ToString();
                                //MessageBox.Show(EB_4);
                            }
                            else
                            {
                            }
                            if (dt.Columns[i].ColumnName.ToString() == "图号")
                            {
                                drawingnum = dt.Rows[j][i].ToString();
                                //MessageBox.Show(partnum);
                            }
                            else
                            {
                            }
                            if (dt.Columns[i].ColumnName.ToString() == "部件编号")
                            {
                                partnum = dt.Rows[j][i].ToString();
                                //MessageBox.Show(partnum);
                            }
                            else
                            {
                            }
                            if (dt.Columns[i].ColumnName.ToString() == "底槽1_CD")
                            {
                                Groove_Bottom_1 = dt.Rows[j][i].ToString();
                                //MessageBox.Show(dt.Rows[0][i].ToString());
                            }
                            else
                            {
                            }
                            if (dt.Columns[i].ColumnName.ToString() == "底槽2_CD")
                            {
                                Groove_Bottom_2 = dt.Rows[j][i].ToString();
                                //MessageBox.Show(partnum);
                            }
                            else
                            {
                            }
                            if (dt.Columns[i].ColumnName.ToString() == "底槽3_CD")
                            {
                                Groove_Bottom_3 = dt.Rows[j][i].ToString();
                                //MessageBox.Show(partnum);
                            }
                            else
                            {
                            }
                            if (dt.Columns[i].ColumnName.ToString() == "底槽4_CD")
                            {
                                Groove_Bottom_4 = dt.Rows[j][i].ToString();
                                //MessageBox.Show(partnum);
                            }
                            else
                            {
                            }
                            if (dt.Columns[i].ColumnName.ToString() == "侧槽1_CD")
                            {
                                Groove_Side_1 = dt.Rows[j][i].ToString();
                                //MessageBox.Show(Groove_Side_1);
                            }
                            else
                            {
                            }
                            if (dt.Columns[i].ColumnName.ToString() == "侧槽2_CD")
                            {
                                Groove_Side_2 = dt.Rows[j][i].ToString();
                                //MessageBox.Show(partnum);
                            }
                            else
                            {
                            }
                            if (dt.Columns[i].ColumnName.ToString() == "侧槽3_CD")
                            {
                                Groove_Side_3 = dt.Rows[j][i].ToString();
                                //MessageBox.Show(partnum);
                            }
                            else
                            {
                            }
                            if (dt.Columns[i].ColumnName.ToString() == "侧槽4_CD")
                            {
                                Groove_Side_4 = dt.Rows[j][i].ToString();
                                //MessageBox.Show(Groove_Side_4);
                            }
                            else
                            {
                            }
                            if (dt.Columns[i].ColumnName.ToString() == "描述")
                            {
                                描述 = dt.Rows[j][i].ToString();
                            }
                            else
                            {
                            }
                            if (dt.Columns[i].ColumnName.ToString() == "厚度")
                            {
                                厚度 = dt.Rows[j][i].ToString();
                            }
                            else
                            {
                            }
                            if (dt.Columns[i].ColumnName.ToString() == "阔度_1")
                            {
                                阔度_1 = dt.Rows[j][i].ToString();
                            }
                            else
                            {
                            }
                            if (dt.Columns[i].ColumnName.ToString() == "阔度_2")
                            {
                                阔度_2 = dt.Rows[j][i].ToString();
                            }
                            else
                            {
                            }
                            if (dt.Columns[i].ColumnName.ToString() == "封边_S1")
                            {
                                封边_S1 = dt.Rows[j][i].ToString();
                            }
                            else
                            {
                            }
                            if (dt.Columns[i].ColumnName.ToString() == "封边_S2")
                            {
                                封边_S2 = dt.Rows[j][i].ToString();
                            }
                            else
                            {
                            }
                            if (dt.Columns[i].ColumnName.ToString() == "封边_S3")
                            {
                                封边_S3 = dt.Rows[j][i].ToString();
                            }
                            else
                            {
                            }
                            if (dt.Columns[i].ColumnName.ToString() == "封边_S4")
                            {
                                封边_S4 = dt.Rows[j][i].ToString();
                            }
                            else
                            {
                            }
                            if (dt.Columns[i].ColumnName.ToString() == "检查标识")
                            {
                                检查标识 = dt.Rows[j][i].ToString();
                            }
                            else
                            {
                            }
                            if (dt.Columns[i].ColumnName.ToString() == "ECN生效")
                            {
                                ECN生效 = dt.Rows[j][i].ToString();
                            }
                            else
                            {
                            }
                            if (dt.Columns[i].ColumnName.ToString() == "旋转标识")
                            {
                                旋转标识 = dt.Rows[j][i].ToString();
                            }
                            else
                            {
                            }
                            if (dt.Columns[i].ColumnName.ToString() == "C_阔度_1")
                            {
                                C_阔度_1 = dt.Rows[j][i].ToString();
                            }
                            else
                            {
                            }
                            if (dt.Columns[i].ColumnName.ToString() == "C_阔度_2")
                            {
                                C_阔度_2 = dt.Rows[j][i].ToString();
                            }
                            else
                            {
                            }
                            if (dt.Columns[i].ColumnName.ToString() == "C_封边_S1")
                            {
                                C_封边_S1 = dt.Rows[j][i].ToString();
                            }
                            else
                            {
                            }
                            if (dt.Columns[i].ColumnName.ToString() == "C_封边_S2")
                            {
                                C_封边_S2 = dt.Rows[j][i].ToString();
                            }
                            else
                            {
                            }
                            if (dt.Columns[i].ColumnName.ToString() == "C_封边_S3")
                            {
                                C_封边_S3 = dt.Rows[j][i].ToString();
                            }
                            else
                            {
                            }
                            if (dt.Columns[i].ColumnName.ToString() == "C_封边_S4")
                            {
                                C_封边_S4 = dt.Rows[j][i].ToString();
                            }
                            else
                            {
                            }
                            if (dt.Columns[i].ColumnName.ToString() == "C_底槽1_CD")
                            {
                                C_底槽1_CD = dt.Rows[j][i].ToString();
                            }
                            else
                            {
                            }
                            if (dt.Columns[i].ColumnName.ToString() == "C_底槽2_CD")
                            {
                                C_底槽2_CD = dt.Rows[j][i].ToString();
                            }
                            else
                            {
                            }
                            if (dt.Columns[i].ColumnName.ToString() == "C_底槽3_CD")
                            {
                                C_底槽3_CD = dt.Rows[j][i].ToString();
                            }
                            else
                            {
                            }
                            if (dt.Columns[i].ColumnName.ToString() == "C_底槽4_CD")
                            {
                                C_底槽4_CD = dt.Rows[j][i].ToString();
                            }
                            else
                            {
                            }
                            if (dt.Columns[i].ColumnName.ToString() == "C_侧槽1_CD")
                            {
                                C_侧槽1_CD = dt.Rows[j][i].ToString();
                            }
                            else
                            {
                            }
                            if (dt.Columns[i].ColumnName.ToString() == "C_侧槽2_CD")
                            {
                                C_侧槽2_CD = dt.Rows[j][i].ToString();
                            }
                            else
                            {
                            }
                            if (dt.Columns[i].ColumnName.ToString() == "C_侧槽3_CD")
                            {
                                C_侧槽3_CD = dt.Rows[j][i].ToString();
                            }
                            else
                            {
                            }
                            if (dt.Columns[i].ColumnName.ToString() == "C_侧槽4_CD")
                            {
                                C_侧槽4_CD = dt.Rows[j][i].ToString();
                            }
                            else
                            {
                            }
                            if (dt.Columns[i].ColumnName.ToString() == "C_封边_T1")
                            {
                                C_封边_T1 = dt.Rows[j][i].ToString();
                            }
                            else
                            {
                            }
                            if (dt.Columns[i].ColumnName.ToString() == "C_封边_T2")
                            {
                                C_封边_T2 = dt.Rows[j][i].ToString();
                            }
                            else
                            {
                            }
                            if (dt.Columns[i].ColumnName.ToString() == "C_封边_T3")
                            {
                                C_封边_T3 = dt.Rows[j][i].ToString();
                            }
                            else
                            {
                            }
                            if (dt.Columns[i].ColumnName.ToString() == "C_封边_T4")
                            {
                                C_封边_T4 = dt.Rows[j][i].ToString();
                            }
                            else
                            {
                            }

                            //MessageBox.Show(dt.Columns[0].ColumnName.ToString());
                            //MessageBox.Show(dt.Rows[0][0].ToString());

                        }

                    }

                    else
                    {
                        MessageBox.Show("dt.Columns.Count !> 0");
                    }

                    if (C_底槽1_CD != "XXXX" && C_侧槽1_CD != "XXXX")
                    {
                        MessageBox.Show("同一边(Side1)不能同时存在底槽和边槽，请核查图纸！部件编号为：" + partnum, "提醒");
                        return false;
                    }
                    else
                    {
                        if (C_底槽1_CD == "XXXX" && C_侧槽1_CD != "XXXX")
                        {
                            Groove_1 = C_侧槽1_CD;
                        }
                        else
                        {
                            if (C_底槽1_CD != "XXXX" && C_侧槽1_CD == "XXXX")
                            {
                                Groove_1 = C_底槽1_CD;
                            }
                            else
                            {
                                Groove_1 = "0-000-000000-0000-0000";
                            }
                        }
                    }

                    if (Groove_1.Length != 22)
                    {
                        MessageBox.Show("Side1导入的槽子程序位数不为22，请检查数据！！部件编号为：" + partnum, "提醒");
                        return false;
                    }

                    if (C_底槽2_CD != "XXXX" && C_侧槽2_CD != "XXXX")
                    {
                        MessageBox.Show("同一边(Side2)不能同时存在底槽和边槽，请核查图纸！部件编号为：" + partnum, "提醒");
                        return false;
                    }
                    else
                    {
                        if (C_底槽2_CD == "XXXX" && C_侧槽2_CD != "XXXX")
                        {
                            Groove_2 = C_侧槽2_CD;
                        }
                        else
                        {
                            if (C_底槽2_CD != "XXXX" && C_侧槽2_CD == "XXXX")
                            {
                                Groove_2 = C_底槽2_CD;
                            }
                            else
                            {
                                Groove_2 = "0-000-000000-0000-0000";
                            }
                        }
                    }
                    if (Groove_2.Length != 22)
                    {
                        MessageBox.Show("Side2导入的槽子程序位数不为22，请检查数据！！部件编号为：" + partnum, "提醒");
                        return false;
                    }
                    else
                    {
                    }

                    if (C_底槽3_CD != "XXXX" && C_侧槽3_CD != "XXXX")
                    {
                        MessageBox.Show("同一边(Side3)不能同时存在底槽和边槽，请核查图纸！部件编号为：" + partnum, "提醒");
                        return false;
                    }
                    else
                    {
                        if (C_底槽3_CD == "XXXX" && C_侧槽3_CD != "XXXX")
                        {
                            Groove_3 = C_侧槽3_CD;
                        }
                        else
                        {
                            if (C_底槽3_CD != "XXXX" && C_侧槽3_CD == "XXXX")
                            {
                                Groove_3 = C_底槽3_CD;
                            }
                            else
                            {
                                Groove_3 = "0-000-000000-0000-0000";
                            }
                        }
                    }
                    if (Groove_3.Length != 22)
                    {
                        MessageBox.Show("Side3导入的槽子程序位数不为22，请检查数据！！部件编号为：" + partnum, "提醒");
                        return false;
                    }
                    else
                    {
                    }

                    if (C_底槽4_CD != "XXXX" && C_侧槽4_CD != "XXXX")
                    {
                        MessageBox.Show("同一边(Side4)不能同时存在底槽和边槽，请核查图纸！部件编号为：" + partnum, "提醒");
                        return false;
                    }
                    else
                    {
                        if (C_底槽4_CD == "XXXX" && C_侧槽4_CD != "XXXX")
                        {
                            Groove_4 = C_侧槽4_CD;
                        }
                        else
                        {
                            if (C_底槽4_CD != "XXXX" && C_侧槽4_CD == "XXXX")
                            {
                                Groove_4 = C_底槽4_CD;
                            }
                            else
                            {
                                Groove_4 = "0-000-000000-0000-0000";
                            }

                            if (Groove_4.Length != 22)
                            {
                                MessageBox.Show("Side4导入的槽子程序位数不为22，请检查数据！！部件编号为：" + partnum, "提醒");
                                return false;
                            }
                            else
                            {
                            }

                            //截取各边厚度
                            /*
                            T1 = EB_1.Substring(2, 2);
                            T2 = EB_2.Substring(2, 2);
                            T3 = EB_3.Substring(2, 2);
                            T4 = EB_4.Substring(2, 2);
                            //MessageBox.Show(T1);
                            */

                            ///Update on 18_Dec_2017 for replacing value by C_? Lucas

                            /*
                            T1 = C_封边_S1.Substring(2, 2);
                            T2 = C_封边_S2.Substring(2, 2);
                            T3 = C_封边_S3.Substring(2, 2);
                            T4 = C_封边_S4.Substring(2, 2);
                            */
                            ///Update on 18_Jan_2018 for replacing value by C_封边_T? ,Then update the logic for Edgeband subprogram generation. Lucas

                            T1 = C_封边_T1.Replace(".", "");//Remove symbol"."
                            T2 = C_封边_T2.Replace(".", "");
                            T3 = C_封边_T3.Replace(".", "");
                            T4 = C_封边_T4.Replace(".", "");

                            #region CompleteString
                            //自动补齐2位数
                            if (T1.Length != 2)
                            {
                                T1 = T1 + "0";
                            }
                            else
                            {
                            }
                            if (T2.Length != 2)
                            {
                                T2 = T2 + "0";
                            }
                            else
                            {
                            }
                            if (T3.Length != 2)
                            {
                                T3 = T3 + "0";
                            }
                            else
                            {
                            }
                            if (T4.Length != 2)
                            {
                                T4 = T4 + "0";
                            }
                            else
                            {
                            }
                            #endregion

                            //MessageBox.Show(旋转标识);
                            if (旋转标识 == "0")
                            {
                                PuHOrientation = "0";
                            }
                            else
                            {
                                PuHOrientation = "270";
                            }

                            #endregion
                        }

                        if (Check_edgebandsuprogram_Grooving_status_SJ(Groove_1, Groove_2, Groove_3, Groove_4, partnum.ToUpper()) == false)
                        {
                            return false;
                        }

                        #region CaseCode Judgement                        

                        if (T1 == "00")
                        {
                            Case_Code_1 = "CXXXXXX";
                            //PB_Side_1.Visible = false;
                        }
                        else
                        {
                            if (T3 == "00" && T4 == "00")
                            {
                                Case_Code_1 = ("C" + T1 + T3 + T4).Replace("XX", "00");
                            }
                            else
                            {
                                Case_Code_1 = ("A" + T1 + T3 + T4).Replace("XX", "00");
                                //PB_Side_1.Visible = true;
                            }
                        }

                        if (T2 == "00")
                        {
                            Case_Code_2 = "CXXXXXX";
                            //PB_Side_2.Visible = false;
                        }
                        else
                        {
                            if (T3 == "00" && T4 == "00")
                            {
                                Case_Code_2 = ("C" + T2 + T4 + T3).Replace("XX", "00");
                            }
                            else
                            {
                                Case_Code_2 = ("A" + T2 + T4 + T3).Replace("XX", "00");
                                //PB_Side_2.Visible = true;
                            }
                        }

                        if (T3 == "00")
                        {
                            if (T2 == "00")
                            {
                                Case_Code_3 = "B0000YY";
                            }
                            else
                            {
                                Case_Code_3 = "B00YYXX";
                            }
                        }
                        else
                        {
                            if (T2 == "00" && T1 == "00")
                            {
                                Case_Code_3 = ("C" + T3 + T2 + T1).Replace("XX", "00");
                            }
                            else
                            {
                                Case_Code_3 = ("B" + T3 + T2 + T1).Replace("XX", "00");
                            }
                        }

                        if (T4 == "00")
                        {
                            if (T1 == "00")
                            {
                                Case_Code_4 = "B0000YY";
                            }
                            else
                            {
                                Case_Code_4 = "B00YYXX";
                            }
                        }
                        else
                        {
                            if (T1 == "00" && T2 == "00")
                            {
                                Case_Code_4 = ("C" + T4 + T1 + T2).Replace("XX", "00");
                            }
                            else
                            {
                                Case_Code_4 = ("B" + T4 + T1 + T2).Replace("XX", "00");
                            }
                        }

                        #endregion


                        Get_Sub_Program();

                        DelDuplicated_EDGEBAND_Data_SJ(partnum.ToUpper(), drawingnum.ToUpper()); //update by Bill :add a columns to judge(drawingnum) 

                        //Insert_Sub_ProgramP_1();
                        #region Insert_Sub_ProgramP_1

                        string sql1 = string.Empty;
                        sql1 = sql1 + "INSERT INTO [Edgeband_Program].[dbo].[EdgebandProgram] (PartNumber,DRAWINGNO,DESCRIPTION,RUN_NUMBER,WORKCYCLE,SUBPROGRAM_FORMATTING,SUBPROGRAM_EDGEBANDING,SUBPROGRAM_CORNERWORKING,SUBPROGRAM_GROOVING,WIDTH,LENGTH,THICKNESS,OFFCUT_DIMENSION,EDGING_CODE,DOWEL)";
                        //sql1 = sql1 + "VALUES('" + partnum + "',N'" + drawingnum + "',N'" + 描述 + "','" + "1" + "'," + "0" + ",N'" + Sub_Pro_Format_1 + "',N'" + Sub_Pro_Edge_1 + "',N'" + Sub_Pro_Corner_1 + "',N'" + Groove_1 + "',N'" + 阔度_2 + "',N'" + 阔度_1 + "','" + 厚度 + "','" + "2.00" + "','" + 封边_S1 + "','" + "0" + "')";
                        //Update on 18_Dec_2017 for replacing value by C_? Lucas
                        sql1 = sql1 + "VALUES('" + partnum.ToUpper() + "',N'" + drawingnum.ToUpper() + "',N'" + 描述 + "','" + "1" + "'," + "0" + ",N'" + Sub_Pro_Format_1 + "',N'" + Sub_Pro_Edge_1 + "',N'" + Sub_Pro_Corner_1 + "',N'" + Groove_1 + "',N'" + C_阔度_1 + "',N'" + C_阔度_2 + "','" + 厚度 + "','" + "2.00" + "','" + C_封边_S1 + "','" + "0" + "')";

                        int i1 = BaseBuildSql.ExecuteNonQuery(sql1); //执行并返回受影响的行数                   

                        #endregion

                        #region Insert_Sub_ProgramP_2

                        string sql2 = string.Empty;
                        sql2 = sql2 + "INSERT INTO [Edgeband_Program].[dbo].[EdgebandProgram] (PartNumber,DRAWINGNO,DESCRIPTION,RUN_NUMBER,WORKCYCLE,SUBPROGRAM_FORMATTING,SUBPROGRAM_EDGEBANDING,SUBPROGRAM_CORNERWORKING,SUBPROGRAM_GROOVING,WIDTH,LENGTH,THICKNESS,OFFCUT_DIMENSION,EDGING_CODE,DOWEL)";
                        //sql2 = sql2 + "VALUES('" + partnum + "',N'" + drawingnum + "',N'" + 描述 + "','" + "2" + "'," + "180" + ",N'" + Sub_Pro_Format_2 + "',N'" + Sub_Pro_Edge_2 + "',N'" + Sub_Pro_Corner_2 + "',N'" + Groove_2 + "',N'" + 阔度_2 + "',N'" + 阔度_1 + "','" + 厚度 + "','" + "2.00" + "','" + 封边_S2 + "','" + "0" + "')";
                        //Update on 18_Dec_2017 for replacing value by C_? Lucas
                        sql2 = sql2 + "VALUES('" + partnum.ToUpper() + "',N'" + drawingnum.ToUpper() + "',N'" + 描述 + "','" + "2" + "'," + "180" + ",N'" + Sub_Pro_Format_2 + "',N'" + Sub_Pro_Edge_2 + "',N'" + Sub_Pro_Corner_2 + "',N'" + Groove_2 + "',N'" + C_阔度_1 + "',N'" + C_阔度_2 + "','" + 厚度 + "','" + "2.00" + "','" + C_封边_S2 + "','" + "0" + "')";

                        int i2 = BaseBuildSql.ExecuteNonQuery(sql2); //执行并返回受影响的行数

                        #endregion

                        #region Insert_Sub_ProgramP_3

                        string sql3 = string.Empty;
                        sql3 = sql3 + "INSERT INTO [Edgeband_Program].[dbo].[EdgebandProgram] (PartNumber,DRAWINGNO,DESCRIPTION,RUN_NUMBER,WORKCYCLE,SUBPROGRAM_FORMATTING,SUBPROGRAM_EDGEBANDING,SUBPROGRAM_CORNERWORKING,SUBPROGRAM_GROOVING,WIDTH,LENGTH,THICKNESS,OFFCUT_DIMENSION,EDGING_CODE,DOWEL)";
                        //sql3 = sql3 + "VALUES('" + partnum + "',N'" + drawingnum + "',N'" + 描述 + "','" + "3" + "'," + "90" + ",N'" + Sub_Pro_Format_3 + "',N'" + Sub_Pro_Edge_3 + "',N'" + Sub_Pro_Corner_3 + "',N'" + Groove_3 + "',N'" + 阔度_2 + "',N'" + 阔度_1 + "','" + 厚度 + "','" + "2.00" + "','" + 封边_S3 + "','" + "0" + "')";
                        //Update on 18_Dec_2017 for replacing value by C_? Lucas
                        sql3 = sql3 + "VALUES('" + partnum.ToUpper() + "',N'" + drawingnum.ToUpper() + "',N'" + 描述 + "','" + "3" + "'," + "90" + ",N'" + Sub_Pro_Format_3 + "',N'" + Sub_Pro_Edge_3 + "',N'" + Sub_Pro_Corner_3 + "',N'" + Groove_3 + "',N'" + C_阔度_1 + "',N'" + C_阔度_2 + "','" + 厚度 + "','" + "2.00" + "','" + C_封边_S3 + "','" + "0" + "')";

                        int i3 = BaseBuildSql.ExecuteNonQuery(sql3); //执行并返回受影响的行数

                        #endregion

                        #region Insert_Sub_ProgramP_4                     
                        string sql4 = string.Empty;
                        sql4 = sql4 + "INSERT INTO [Edgeband_Program].[dbo].[EdgebandProgram] (PartNumber,DRAWINGNO,DESCRIPTION,RUN_NUMBER,WORKCYCLE,SUBPROGRAM_FORMATTING,SUBPROGRAM_EDGEBANDING,SUBPROGRAM_CORNERWORKING,SUBPROGRAM_GROOVING,WIDTH,LENGTH,THICKNESS,OFFCUT_DIMENSION,EDGING_CODE,DOWEL,ORIENTATION_PH)";
                        //sql4 = sql4 + "VALUES('" + partnum + "',N'" + drawingnum + "',N'" + 描述 + "','" + "4" + "'," + "270" + ",N'" + Sub_Pro_Format_4 + "',N'" + Sub_Pro_Edge_4 + "',N'" + Sub_Pro_Corner_4 + "',N'" + Groove_4 + "',N'" + 阔度_2 + "',N'" + 阔度_1 + "','" + 厚度 + "','" + "2.00" + "','" + 封边_S4 + "','" + "0" + "','" + PuHOrientation + "')";
                        //Update on 18_Dec_2017 for replacing value by C_? Lucas
                        sql4 = sql4 + "VALUES('" + partnum.ToUpper() + "',N'" + drawingnum.ToUpper() + "',N'" + 描述 + "','" + "4" + "'," + "270" + ",N'" + Sub_Pro_Format_4 + "',N'" + Sub_Pro_Edge_4 + "',N'" + Sub_Pro_Corner_4 + "',N'" + Groove_4 + "',N'" + C_阔度_1 + "',N'" + C_阔度_2 + "','" + 厚度 + "','" + "2.00" + "','" + C_封边_S4 + "','" + "0" + "','" + PuHOrientation + "')";
                        int i4 = BaseBuildSql.ExecuteNonQuery(sql4); //执行并返回受影响的行数

                        #endregion
                    }
                }
            }

            #region Set Empty Value for EDGING_CODE which values are "%XX%"

            string sqlcorecndate = string.Empty;
            sqlcorecndate = sqlcorecndate + "UPDATE [Edgeband_Program].[dbo].[EdgebandProgram] SET EDGING_CODE='' WHERE EDGING_CODE LIKE '%XX%'";
            int Exesqlecn = BaseBuildSql.ExecuteNonQuery(sqlcorecndate); //执行并返回受影响的行数
            #endregion
            return true;
        }
        public bool Check_edgebandsuprogram_Grooving_status_SJ(string Grooving_1, string Grooving_2, string Grooving_3, string Grooving_4, string partnumber)
        {
            try
            {
                string sql = string.Empty;
                sql = sql + "SELECT NAME FROM [Lamex_1207].[dbo].[TBL_SUBPROGRAMS](NOLOCK) WHERE NAME = '" + Grooving_1 + "'";
                sql = sql + "SELECT NAME FROM [Lamex_1207].[dbo].[TBL_SUBPROGRAMS](NOLOCK) WHERE NAME = '" + Grooving_2 + "'";
                sql = sql + "SELECT NAME FROM [Lamex_1207].[dbo].[TBL_SUBPROGRAMS](NOLOCK) WHERE NAME = '" + Grooving_3 + "'";
                sql = sql + "SELECT NAME FROM [Lamex_1207].[dbo].[TBL_SUBPROGRAMS](NOLOCK) WHERE NAME = '" + Grooving_4 + "'";
                DataSet ds1 = BaseBuildSql.GetDataSetBySql(sql);
                if (ds1.Tables[0].Rows.Count <= 0)
                {
                    MessageBox.Show(partnumber + "的槽子程序1: " + Grooving_1 + " 在数据库不存在!", "提醒");
                    return false;
                }
                if (ds1.Tables[1].Rows.Count <= 0)
                {
                    MessageBox.Show(partnumber + "的槽子程序2: " + Grooving_2 + " 在数据库不存在!", "提醒");
                    return false;
                }
                if (ds1.Tables[2].Rows.Count <= 0)
                {
                    MessageBox.Show(partnumber + "的槽子程序3: " + Grooving_3 + " 在数据库不存在!", "提醒");
                    return false;
                }
                if (ds1.Tables[3].Rows.Count <= 0)
                {
                    MessageBox.Show(partnumber + "的槽子程序4: " + Grooving_4 + " 在数据库不存在!", "提醒");
                    return false;
                }
                else
                {
                    return true;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                return false;
            }
        }
        private void Get_Sub_Program()
        {

            string sql_Side_1 = string.Empty;
            sql_Side_1 = sql_Side_1 + "SELECT CASE_CODE,SUBPROGRAM_FORMATTING,SUBPROGRAM_EDGEBANDING,SUBPROGRAM_CORNERWORKING FROM [Edgeband_Program].[dbo].[Case_Code](NOLOCK) WHERE CASE_CODE='" + Case_Code_1 + "'";
            DataSet ds1 = BaseBuildSql.GetDataSetBySql(sql_Side_1);
            Sub_Pro_Format_1 = ds1.Tables[0].Rows[0]["SUBPROGRAM_FORMATTING"].ToString();
            Sub_Pro_Edge_1 = ds1.Tables[0].Rows[0]["SUBPROGRAM_EDGEBANDING"].ToString();
            Sub_Pro_Corner_1 = ds1.Tables[0].Rows[0]["SUBPROGRAM_CORNERWORKING"].ToString();

            string sql_Side_2 = string.Empty;
            sql_Side_2 = sql_Side_2 + "SELECT CASE_CODE,SUBPROGRAM_FORMATTING,SUBPROGRAM_EDGEBANDING,SUBPROGRAM_CORNERWORKING FROM [Edgeband_Program].[dbo].[Case_Code](NOLOCK) WHERE CASE_CODE='" + Case_Code_2 + "'";
            DataSet ds2 = BaseBuildSql.GetDataSetBySql(sql_Side_2);
            Sub_Pro_Format_2 = ds2.Tables[0].Rows[0]["SUBPROGRAM_FORMATTING"].ToString();
            Sub_Pro_Edge_2 = ds2.Tables[0].Rows[0]["SUBPROGRAM_EDGEBANDING"].ToString();
            Sub_Pro_Corner_2 = ds2.Tables[0].Rows[0]["SUBPROGRAM_CORNERWORKING"].ToString();

            string sql_Side_3 = string.Empty;
            sql_Side_3 = sql_Side_3 + "SELECT CASE_CODE,SUBPROGRAM_FORMATTING,SUBPROGRAM_EDGEBANDING,SUBPROGRAM_CORNERWORKING FROM [Edgeband_Program].[dbo].[Case_Code](NOLOCK) WHERE CASE_CODE='" + Case_Code_3 + "'";
            DataSet ds3 = BaseBuildSql.GetDataSetBySql(sql_Side_3);
            Sub_Pro_Format_3 = ds3.Tables[0].Rows[0]["SUBPROGRAM_FORMATTING"].ToString();
            Sub_Pro_Edge_3 = ds3.Tables[0].Rows[0]["SUBPROGRAM_EDGEBANDING"].ToString();
            Sub_Pro_Corner_3 = ds3.Tables[0].Rows[0]["SUBPROGRAM_CORNERWORKING"].ToString();


            string sql_Side_4 = string.Empty;
            sql_Side_4 = sql_Side_4 + "SELECT CASE_CODE,SUBPROGRAM_FORMATTING,SUBPROGRAM_EDGEBANDING,SUBPROGRAM_CORNERWORKING FROM [Edgeband_Program].[dbo].[Case_Code](NOLOCK) WHERE CASE_CODE='" + Case_Code_4 + "'";
            DataSet ds4 = BaseBuildSql.GetDataSetBySql(sql_Side_4);
            Sub_Pro_Format_4 = ds4.Tables[0].Rows[0]["SUBPROGRAM_FORMATTING"].ToString();
            Sub_Pro_Edge_4 = ds4.Tables[0].Rows[0]["SUBPROGRAM_EDGEBANDING"].ToString();
            Sub_Pro_Corner_4 = ds4.Tables[0].Rows[0]["SUBPROGRAM_CORNERWORKING"].ToString();

        }
        private void DelDuplicated_EDGEBAND_Data_SJ(string PartNumber, string drawingnum)
        {
            try
            {
                string sql = string.Empty;
                sql = sql + "SELECT * FROM [Edgeband_Program].[dbo].[EdgebandProgram](NOLOCK) WHERE PartNumber = '" + PartNumber + "' and DRAWINGNO='" + drawingnum + "'";
                DataSet ds1 = BaseBuildSql.GetDataSetBySql(sql);
                if (ds1.Tables[0].Rows.Count != 0)
                {
                    string sql1 = string.Empty;
                    sql1 = sql1 + "DELETE FROM [Edgeband_Program].[dbo].[EdgebandProgram] WHERE PartNumber = '" + PartNumber + "' and DRAWINGNO='" + drawingnum + "' ";
                    int j = BaseBuildSql.ExecuteNonQuery(sql1);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
        #endregion

    }
}
